export const systemInfo = {
	data: () => ({
		statusBarHeight: 0,
		navigationBarHeight: 0,
		navHeight: 0,
		windowHeight: 0, // 可使用窗口高度
		safeBottom:0,
	}),

	methods: {
		// 获取设备信息
		getSystemInfo() {
			let info = uni.getSystemInfoSync()
			this.statusBarHeight = getApp().globalData.statusBarHeight
			this.navigationBarHeight = getApp().globalData.navigationBarHeight
			this.windowHeight = info.windowHeight
			this.navHeight = getApp().globalData.navHeight
			this.safeBottom = info.screenHeight - info.safeArea.bottom
		},
	},
}

export const transform = {

	methods: {
		priceTransform(value = 0, fixed = 2, amountMark = '￥') {
			return `${amountMark}${(parseInt(value) / 100).toFixed(fixed).replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')}`;
		},
		formatDateTime(timestamp) {
			// 创建 Date 对象  
			var date = new Date(timestamp)

			// 获取年、月、日、时、分、秒  
			var year = date.getFullYear()
			var month = date.getMonth() + 1
			var day = date.getDate()
			var hour = date.getHours()
			var minute = date.getMinutes()
			var second = date.getSeconds()

			// 格式化输出日期时间  
			var formattedDateTime = year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day :
					day) + ' ' +
				(hour < 10 ? '0' : '') + hour + ':' + (minute < 10 ? '0' : '') + minute + ':' + (second < 10 ? '0' :
					'') +
				second

			return formattedDateTime
		},
		imageSrc(images) {
			images = images || ''
			let imgs = images.split(',')
			return imgs[0] || '/static/logo.png'
		},
		distanceText(dis) {
			if (dis > 1000) {
				return (dis / 1000).toFixed(0) + ' km'
			}
			return dis + ' m'
		}
	}
}